<!--  -->
<template>
  <view>
    <anttab @switchTab="changeTab"></anttab>
    <goodlist :param="param" v-if="param"></goodlist>
  </view>
</template>

<script>
import anttab from '@/components/antTab'
import goodlist from '@/components/goodlist'

export default {
  data () {
    return {
      param: Object
    }
  },
  components: {anttab, goodlist},

  computed: {},

  methods: {
    changeTab (type) {
      this.param.q.sort = type
      this.param.q.min_id = 0
      getComponentByTag(this, 'goodlist').loadGood()
    }
  },
  onLoad () {
    this.param = JSON.parse(this.$root.$mp.query.param)
  },
  // 小程序原生触底方法
  onReachBottom () {
    // this.$ref  为空 mpvue不支持此方法
   // this.$children[0].loadmore()
    if (!this.param.noscroll) {
      getComponentByTag(this, 'goodlist').loadmore()
    }
  },
  onUnload () {
    this.param = null
  }
}

// 获取子组件权宜之计 tag -> 子组件名
export const getComponentByTag = (parent, tag) => {
  for (let c of parent.$children) {
    if (c.$options._componentTag === tag) {
      return c
    }
  }
}

</script>
<style lang='less' scoped>
</style>